home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Loadstar 10
/
010.d81
/
dos #25
< prev
next >
Wrap
Text File
|
2022-08-26
|
3KB
|
185 lines
DOS and don'ts -- Part 25
by Jimmy Weiler
Still confused? Let's graph it out.
Here's our file after we write two
names into it.
{CBM-A} Byte 1 {CBM-A} Byte 13
! !
V V
{CBM-A}--->SCHLABOTNIK/8687247/ <68 nulls>
! {CBM-A}->WELLS/ 6363088/ <68 nulls>
! !
! {CBM-Z}- Record 2
{CBM-Z}--- Record 1
Each record has two fields, the name
and the phone number, separated by
carriage returns and padded out to the
next field with CHR$(0). The rest of
the 89 characters in each record are
CHR$(0). The first PRINT# in the
first record started at character 1.
"SCHLABOTNIK" is 11 letters long, plus
one carriage return, for 12 letters.
The second PRINT# in record 1 started
where we told it to--at character 13.
When we wrote the second record,
the first PRINT# started at the first
character and took 6 characters to
finish. The second PRINT# started at
character 13, so there are 6 null
characters between the end of the
first field and the start of the
second. These nulls will have no
effect when we read them back, so
don't worry about them.
Doing a POSITION every time you use
PRINT# gets old very quickly, and it
consumes valuable computer time, and
it uses extra memory space -- in other
words, there's an easier way to write
the fields into a RELative file's
record.
Start, as before, by POSITIONing
to the start of the record:
100 PRINT#15,"P"CHR$(4)CHR$(1)CHR$(0)
CHR$(1)
Then print all the fields at once, in
a single PRINT# statement:
200 PRINT#3,"SCHLABOTNIK"CHR$(13)
"8687247"
Of course, in most programs, all the
fields would already be contained in
strings, and the code would look more
like this:
150 CR$ = CHR$(13)
200 PRINT#3,NA$ CR$ PH$
One drawback of this technique is
that you never know just where in a
record any of the fields (except the
first) can be found. This is no
problem if you intend always to read
or write a whole record, but if you
ever want to read just one field from
the record, or update just part of a
record, you will need to know exactly
what byte to POSITION to.
One of the major advantages of REL
files over SEQ files is that you CAN
update a small piece of a REL file
without having any effect on the rest
of the file. But take care! Every
time you PRINT# into a record of a
RELative file, the entire contents of
that record from that point on will be
erased.
Here's an example: Your record has
this in it:
WILLOW/PINE/ MAPLE/ BIRCH/
You want to replace PINE with OAK, so
you :
PRINT#15,"P"CHR$(4)CHR$(LB)CHR$(HB)
CHR$(8):PRINT#3,"OAK"
Now your record has:
WILLOW/OAK/
-- obviously not what you intended.
The safest way to update a record is
to read the entire record, change the
values in the appropriate variables,
and write the whole thing back onto
the disk.
-------- continued in Part 26 --------